<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:a4j="http://richfaces.org/a4j"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:zanata="http://java.sun.com/jsf/composite/zanata"
  template="../WEB-INF/template/template.xhtml">

  <f:metadata>
    <f:event type="preRenderView" listener="#{identity.checkRole('admin')}"/>
  </f:metadata>

  <ui:define name="page_title">#{msgs['jsf.ProcessManager']}</ui:define>

  <ui:define name="center_content">
    <a4j:region>
      <h:form>
        <a4j:poll interval="2000" render="process_form,progress"/>
      </h:form>
    </a4j:region>

    <div class="g">
      <div class="g__item l--push-bottom-half">
        <p class="txt--meta l--push-all-0">
          <a href="/admin/home">
            #{msgs['jsf.Administration']}
          </a>
        </p>

        <div class="l--push-bottom-half">
          <h1 class="l--push-all-0">
            <i class="i--small i--clock txt--neutral i--left"></i>
            #{msgs['jsf.ProcessManager']}
          </h1>
        </div>

        <h:panelGroup layout="block"  styleClass="panel l--push-top-1" id="progress">
          <div class="panel__header">
            <h2 class="panel__heading--small">
            #{msgs['jsf.processmanager.currentStates']}
            </h2>
          </div>
          <div class="l--pad-all-half txt--meta l--push-top-quarter">
              #{msgs['jsf.processmanager.TotalRunning']}<span class="l--push-left-quarter l--push-right-half badge badge--highlight">
              #{processManagerAction.runningCount}</span>

              #{msgs['jsf.processmanager.TotalFinished']}<span class="l--push-left-quarter badge">
              #{processManagerAction.stoppedCount}</span>
          </div>
        </h:panelGroup>
      </div>

      <div class="g__item l--push-top-1">
        <div class="panel">

          <h:form id="process_form" styleClass="l--push-bottom-0">
            <h:panelGroup layout="block"  styleClass="l--pad-all-half"
              rendered="#{empty processManagerAction.runningProcesses}">
              <p class="txt--meta">#{msgs['jsf.processmanager.process.empty']}</p>
            </h:panelGroup>

            <ui:fragment rendered="#{not empty processManagerAction.runningProcesses}">
              <ul class="list--stats">
                <ui:repeat value="#{processManagerAction.runningProcesses}" var="handle">
                  <li
                    title="#{handle.done ? msgs['jsf.processmanager.status.Finished'] : msgs['jsf.processmanager.status.Running']}">
                    <div class="list__item__content">
                      <div class="list__item__info">
                        <span class="zeta #{handle.done ? 'txt--understated' : 'txt--highlight'}">
                          #{handle.toString()}
                        </span>
                        <a4j:commandButton action="#{processManagerAction.cancel(handle)}"
                          value="#{msgs['jsf.Cancel']}"
                          rendered="#{not handle.done}" styleClass="button button--danger l--push-left-half l--push-bottom-quarter"/>

                        <span class="list__item__meta txt--warning">
                          <ui:fragment rendered="#{handle.done}">
                            #{msgs['jsf.processmanager.status.Finished']}
                          </ui:fragment>
                          <ui:fragment rendered="#{not handle.done}">
                            #{msgs.format('jsf.processmanager.progress', handle.currentProgress, handle.maxProgress)}
                          </ui:fragment>
                        </span>
                      </div>
                      <div class="list__item__stats">
                        <ui:fragment rendered="#{not handle.done}">
                          <zanata:loader type="loader--small" layout="inline"/>
                        </ui:fragment>

                        <h:panelGroup layout="span" styleClass="txt--understated" rendered="#{handle.done}">
                          <span
                            class="txt--hero">#{handle.executingTime}</span>
                          <span class="stats__unit txt--lowercase">
                            #{msgs['jsf.processmanager.miliseconds']}
                          </span>
                        </h:panelGroup>
                      </div>
                    </div>
                  </li>
                </ui:repeat>
              </ul>
            </ui:fragment>
          </h:form>
        </div>
      </div>
    </div>
  </ui:define>

</ui:composition>
